<%@page import="com.biz.ShopCartBizImpl"%>
<%@page import="com.entity.ShopCart"%>
<%@page import="com.entity.UserInfo"%>
<%@page import="com.biz.ProductBizImpl"%>
<%@page import="com.entity.Product"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>我的购物车</title>
    
	<meta charset="UTF-8">
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="css/showtable.css">
    <link rel="stylesheet" type="text/css" href="css/modle.css">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
	<style type="text/css">
		form{
			width: 95%;
			margin: 0px auto;
		}
		.title-table{
			background-image: linear-gradient(225deg, #D4FFEC 0%, #57F2CC 48%, #4596FB 100%);
			padding: 10px;
			margin-bottom: 0px;
			width: 500px;
			padding-left: 20px;
			border-radius: 25px;
			color: white;
			text-align: left;
		}
		.title{
			float: right;
		}
		.title-link{
			display: inline-block;
			float: left;
			margin-top: 20px;
		}
		input[name="num"]{
			text-align: center;
			width: 40px;
		}
		#settlement>span{
			margin-right: 20px;
		}
		#settlement>a{
			display: inline-block;
			height: 20px;
			background: orange;
			color: white;
			padding: 10px 10px 15px 10px;
			margin: 5px;
			border: 1px solid orange;
			border-radius: 5px;
			font-size: 18px;
			text-decoration: none;
		}
		#settlement>a:hover{
			background: red;
			color: white;
		}
		#totalprice{
			font-size: 18px;
			color: red;
		}
		.shopcarts-body>td{
			line-height: 80px;
			text-align: center;
		}
		.shopcarts-body td:NTH-CHILD(5){
			width: 500px;
			line-height: 80px;
		}
		.shopcarts-body a{
			color: blue;
		}
		.shopcarts-body a:hover{
			color: red;
			text-decoration: underline;
		}
	</style>
	<script type="text/javascript">
		function delShopCart( delid ){
			if(confirm("你确定要删除吗？")){
				location="user/do/doDelShopCart.jsp?id="+delid;
			}
		}
		function submitform( isdo ){
			if(isdo=='del'){
				if(confirm("你确定要删除吗？")){
					$("#scForm").attr("action","user/do/doDelShopCarts.jsp");
				}
			}else{
				$("#scForm").attr("action","user/address?orders=2");
			}
			$("#scForm").submit();
		}
	</script>
  </head>
  <body class="mybody">
  	<div class="main">
  		<div class="index-title">
  			<iframe src="index-b-elem/header.jsp" frameborder="0" id="title-if"></iframe>
  		</div>
	    <div class="main-body-div">
	  		<form action="" method="post" id="scForm">
	  			<input type="hidden" name="orders"/>
			  	<h2 class="title-table">我的购物车</h2>
			  	<span class="title-link">
				  		<a href="javascript:submitform('del')">删除所选商品</a>
				</span>
			  	<span class="title">
				  	<span id="settlement">
				  		<span id="totalprice">总价：￥</span>
				  		<a href="index.jsp" target="_parent">继续购买</a>
				  		<a href="javascript:submitform('set')">结&nbsp;&nbsp;&nbsp;算</a>
				  	</span>
			  	</span>
			  	<table>
			  		<tr>
			  			<td><input type="checkbox" id="all" checked="checked"/>全选</td>
			  			<td>商品名称</td>
			  			<td>商品价格</td>
			  			<td>商品数量</td>
			  			<td>留言</td>
			  			<td>操作</td>
			  		</tr>
			    <%			
			    	UserInfo us=(UserInfo)session.getAttribute("loger");
			    	List<ShopCart> list=new ShopCartBizImpl().showMyShopCart(us.getId());
			    	for(ShopCart sc:list){
			    %>
			   		<tr class="shopcarts-body">
			   			<td><input type="checkbox" name="check"  checked="checked" value="<%=sc.getId()%>"/></td>
			   			<td><a href="proInfo.jsp?id=<%=sc.getPid()%>"><%=sc.getPname()%></a></td>
			   			<td name="price"><%=sc.getPrice()%></td>
			   			<td><input type="number" name="num" id="num<%=sc.getId() %>" min="1" value="<%=sc.getNum()%>" onchange="changethisprice(<%=sc.getId() %>)"/></td>
			   			<td><%=sc.getComments()%></td>
			   			<td>
			   				<a href="javascript:delShopCart(<%=sc.getId()%>)">删除</a>
			   			</td>
			   		</tr>
			    <%
			    	}
			    %>
		    	</table>
	   		</form>
	 	</div>
	 	<div class="index-footer">
  			<iframe src="index-b-elem/footer.jsp" frameborder="0" id="title-if"></iframe>
  		</div>
   	</div>
  </body>
  
  <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
	<script type="text/javascript">
		function delPro( delid ){
			var flag=confirm("确定要删除吗?");
			if(flag){
			}
		}
		function checkall(){
			var flag=document.getElementById("all").checked;
			var checks=document.getElementsByName("check");
			for(var i=0;i<checks.length;i++){
				checks[i].checked=flag;
			}
			sumtotalprice();
		}
		sumtotalprice();
		function delManyPro(){
			if(confirm("确定要删除这些商品吗？")){
				$("#delManyForm").submit();
			}
		}
		function changethisprice( scid ){
			sumtotalprice();
			var num=$("#num"+scid).val();
			location="user/do/doModShopCart.jsp?id="+scid+"&num="+num;
		}
		function sumtotalprice(){
			var pros=document.getElementsByName("check");
			var sum=0;
			for(var i=0;i<pros.length;i++){
				if(pros[i].checked){
					var pro=$(pros[i]);
					var num=pro.parents("tr").find("td input[name='num']").val();
					var price=pro.parents("tr").find("td[name='price']").html();
					sum=parseFloat(num*price+parseFloat(sum)).toFixed(2);
				}
			}
			$("#totalprice").html("总价：￥"+sum);
		}
		$(function(){
			$("#all").click(function(){
				checkall();
			});
			$("input[name='check']").click(function(){
				sumtotalprice();
			});
		});
	</script>
</html>
<jsp:include page="../mybrowse.jsp"></jsp:include>